package com.ch.playandroid.repository

import com.ch.common.net.RetrofitManager
import com.ch.common.net.RetrofitManager.await
import com.ch.common.net.RetrofitManager.launcherNetApi
import com.ch.playandroid.netApi.WebServiceApi
import kotlinx.coroutines.Dispatchers

object ArticleRepository {
    private var mWebServiceApi: WebServiceApi =
        RetrofitManager.createServiceApi(WebServiceApi::class.java)

    //获取首页--轮播数据
    fun getBannerData() = launcherNetApi(Dispatchers.IO) {
        val bean = mWebServiceApi.getBannerData().await()
        if (bean.errorCode == 0) {
            Result.success(bean)
        } else {
            Result.failure(RuntimeException(""))
        }
    }

    fun getArticleData(numberPager: Int) = launcherNetApi(Dispatchers.IO) {
        val bean = mWebServiceApi.getArticleData(numberPager).await()
        if (bean.errorCode == 0) {
            Result.success(bean)
        } else {
            Result.failure(RuntimeException(""))
        }
    }
}